###############################################################################
# SuperLinks                                                                  #
# Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk)                #
###############################################################################
# This program is free software; you can redistribute it and/or modify it     #
# under the terms of the GNU General Public License as published by the Free  #
# Software Foundation; either version 2 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   #
# more details.                                                               ##                                                                             #
# You should have received a copy of the GNU General Public License along     #
# with this program; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 #
###############################################################################
# ControlPanel/Output/ModifyAdmin.pm.pl -> ModifyAdmin module                 #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package Skin::CP::ModifyAdmin;

BEGIN { require "System.pm.pl"; import System qw($SYSTEM); }
BEGIN { require "General.pm.pl"; import General qw($GENERAL); }
require "Standard.pm.pl";

use HTML::Dialog;
use strict;

sub new {
  my ($class) = @_;
  my $self    = {};
  return bless ($self, $class);
}

sub DESTROY { }

###############################################################################
# show subroutine
sub show {
  my $self = shift;
  my %in = (input => undef, error => "", @_);

  my $LANGUAGE = {
    "MISSING" => {
      "USERNAME"      => qq~<li>You didn't fill in the "Username" field.~,
      "PASSWORD"      => qq~<li>You didn't fill in the "Password" field.~,
      "NAME"          => qq~<li>You didn't fill in the "Name" field.~,
      "LEVEL"         => qq~<li>You didn't fill in the "Level" field.~,
      "STATUS"        => qq~<li>You didn't fill in the "Status" field.~
    },
    "TOOLONG" => {
      "USERNAME"      => qq~<li>The value for the "Username" field must be 48 characters or less.~,
      "PASSWORD"      => qq~<li>The value for the "Password" field must be 64 characters or less.~,
      "NAME"          => qq~<li>The value for the "Name" field must be 128 characters or less.~
    },
    "INVALID" => {
      "LEVEL"         => qq~<li>The value you entered for the "Level" field is invalid.~
    },
    "ALREADYEXISTS" => {
      "USERNAME"      => qq~<li>The value you entered for the "Username" field already exists.~
    },
    "ERROR"         => qq~<p><font class="error">There were errors:<ul>[%error%]</ul></font>~
  };

  $in{'error'} = &Standard::ProcessError(LANGUAGE => $LANGUAGE, ERROR => $in{'error'});

  #----------------------------------------------------------------------#
  # Printing page...                                                     #

  my $Dialog = HTML::Dialog->new();

  my $Body = $Dialog->TableRow(items => [{ body => "Please fill out all the required (<font class=\"form-required\"><b>*</b></font>) fields:".$in{'error'}, colspan => "2" }]);

  $Body .= $Dialog->FormTextBox(
    value     => $in{'input'}->{'ADMIN'}->{'USERNAME'},
    subject   => "Username"
  );
  
  $Body .= $Dialog->FormTextBox(
    name      => "FORM_PASSWORD",
    value     => $in{'input'}->{'ADMIN'}->{'PASSWORD'},
    subject   => "Password",
    required  => 1
  );

  $Body .= $Dialog->FormTextBox(
    name      => "FORM_NAME",
    value     => $in{'input'}->{'ADMIN'}->{'NAME'},
    subject   => "Name",
    required  => 1
  );

  my @options = &Standard::MapArray({ value => "\${ID}", label => "\${TITLE}" }, $in{'input'}->{'LEVELS'});
  
  $Body .= $Dialog->FormSelectBox(
    name      => "FORM_LEVEL",
    value     => $in{'input'}->{'ADMIN'}->{'LEVEL'},
    subject   => "Level",
    required  => 1,
    items     => \@options
  );
  
  $Body .= $Dialog->FormRadio(
    name      => "FORM_STATUS",
    value     => $in{'input'}->{'ADMIN'}->{'STATUS'},
    subject   => "Status",
    required  => 1,
    items     => [
      { value => "0", label => "Inactive" },
      { value => "1", label => "Active" }
    ], join => "&nbsp;"
  );

  $Body .= $Dialog->FormButton(
    items => [
      { type => "submit", value => "Modify" },
      { type => "reset", value => "Cancel" }
    ], join => "&nbsp;"
  );

  $Body = $Dialog->Table(body => $Body);
  $Body = $Dialog->StandardPage(
    body        => $Body,
    header      => "Modify an Admin",
    form        => 1,
    head_extra  => "<script src=\"$SYSTEM->{'PUBLIC_URL'}/functions.js\"></script>",
    hiddens     => [
      { name => "Referer", value => $SL::QUERY{'Referer'} },
      { name => "USERNAME", value => $in{'input'}->{'ADMIN'}->{'USERNAME'} },
      { name => "action", value => "DoModifyAdmin" },
      { name => "CP", value => "1" },
      { name => "SID", value => $SL::ADMIN{'SID'} }
    ],
    ($in{'input'}->{'ADMIN'}->{'USERNAME'} ne $SL::ADMIN{'USERNAME'} ? (toolbar => [
      { type => "divider" },
      { type => "icon", url => "javascript:ConfirmRemove('$SYSTEM->{'SCRIPT_URL'}?CP=1&action=DoRemoveAdmins&USERNAME=$in{'input'}->{'ADMIN'}->{'USERNAME'}&Referer=".$SL::CGI->escape($SL::CGI->escape($SL::QUERY{'Referer'}))."&SID=$SL::ADMIN{'SID'}');", icon => "Toolbar/remove.gif", caption => "Remove" }
    ]) : ())
  );
}

###############################################################################
# do subroutine
sub do {
  my $self = shift;
  my %in = (input => undef, @_);

  #----------------------------------------------------------------------#
  # Printing page...                                                     #

  my $Dialog = HTML::Dialog->new();

  my $Body = $Dialog->TableRow(items => [{ body => "The following admin has been modified:", colspan => 2 }]);

  $Body .= $Dialog->FormTextBox(
    value     => $in{'input'}->{'ADMIN'}->{'USERNAME'},
    subject   => "Username"
  );
  
  $Body .= $Dialog->FormTextBox(
    value     => $in{'input'}->{'RECORD'}->{'PASSWORD'},
    subject   => "Password"
  );

  $Body .= $Dialog->FormTextBox(
    value     => $in{'input'}->{'RECORD'}->{'NAME'},
    subject   => "Name"
  );

  $Body .= $Dialog->FormTextBox(
    value     => $in{'input'}->{'LEVEL'}->{'TITLE'},
    subject   => "Level"
  );

  $Body .= $Dialog->FormTextBox(
    value     => ($in{'input'}->{'RECORD'}->{'STATUS'} ? "Active" : "Inactive"),
    subject   => "Status"
  );

  $Body .= $Dialog->TableDivider(colspan => 2);
  $Body .= $Dialog->TableRow(items => [{ body => "Click <a href=\"".($SL::QUERY{'Referer'} || "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=Admins&SID=$SL::ADMIN{'SID'}")."\">here</a> if you're not redirected in 5 seconds.", colspan => 2 }]);

  $Body = $Dialog->Table(body => $Body);
  $Body = $Dialog->StandardPage(
    body    => $Body,
    header  => "Modify an Admin",
    metas   => [
      { http_equiv => "refresh", content => "5; url=".($SL::QUERY{'Referer'} || "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=Admins&SID=$SL::ADMIN{'SID'}") }
    ]
  );
  
  return $Body;
}

1;